package com.leeon.container.iterator;

import com.leeon.container.foreach.IterableClass;

import java.util.Iterator;

public class MuliIterableClass extends IterableClass {
    public Iterable<String> reversed(){
        return new Iterable<String>() {
            @Override
            public Iterator<String> iterator() {
                return new Iterator<String>() {

                    private int current = words.length - 1;

                    @Override
                    public boolean hasNext() {
                        return current > -1;
                    }

                    @Override
                    public String next() {
                        return words[current--];
                    }

                    @Override
                    public void remove(){
                    }
                };
            }
        };
    }

    public static void main(String[] args){
        MuliIterableClass mic = new MuliIterableClass();
        for (String s : mic.reversed()){
            System.out.print(s + "  ");
        }
        System.out.println();
        for (String s : mic){
            System.out.print(s + "  ");
        }
    }
}
